package com.vanke.vms.management.action;

import java.util.List;

import com.vanke.vms.common.action.BaseAction;
import com.vanke.vms.management.service.ManageUserService;
import com.vanke.vms.common.domain.User;

public class ManageUserAction extends BaseAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = -6872629364905982579L;

	private ManageUserService manageUserService;

	private List<User> applyUserList;
	
	private List<User> forgetPassUserList;
	
	private List<User> allUserList;

	private User modifiedUser;
	

	private String userId;
	
	private String grade;

	private int role;

	public String loadUser(){
		User curUser = (User)session.get("user");
		if(curUser == null)
			return LOGIN;
		if(curUser.getGrade() == 2)
			role = 2;
		else if(curUser.getGrade() == 1)
			role = 1;
		else if(curUser.getGrade() == 0)
			role = 0;
		
		applyUserList = manageUserService.loadUser();
		
		forgetPassUserList = manageUserService.loadForgetPassUser();
		
		allUserList = manageUserService.loadAllUser();
		
		return SUCCESS;
	}
	
	public String modifyUser(){
		manageUserService.modifyUser(modifiedUser);
		return loadUser();
	}
	
	public String loadUserInfo(){
		User curUser = (User)session.get("user");
		if(curUser == null)
			return LOGIN;
		if(curUser.getGrade() == 2)
			role = 2;
		else if(curUser.getGrade() == 1)
			role = 1;
		else if(curUser.getGrade() == 0)
			role = 0;
		
		modifiedUser = manageUserService.loadUserInfo(userId);
		return SUCCESS;
	}
	
	public String deleteUser(){
		manageUserService.deleteUser(Integer.parseInt(userId));
		loadUser();
		return SUCCESS;
	}
	
	public String approveApply(){
		manageUserService.approveApply(Integer.parseInt(userId));
		loadUser();
		return SUCCESS;
	}
	
	public String rejectApply(){
		manageUserService.rejectApply(Integer.parseInt(userId));
		loadUser();
		return SUCCESS;
	}
	
	public String removePass(){
		manageUserService.removePass(Integer.parseInt(userId));
		loadUser();
		return SUCCESS;
	}
	
	//////////////////////////////////////////////////////////////////////

	public User getModifiedUser() {
		return modifiedUser;
	}

	public void setModifiedUser(User modifiedUser) {
		this.modifiedUser = modifiedUser;
	}
	
	public List<User> getAllUserList() {
		return allUserList;
	}

	public void setAllUserList(List<User> allUserList) {
		this.allUserList = allUserList;
	}

	public String getGrade() {
		return grade;
	}

	public void setGrade(String grade) {
		this.grade = grade;
	}

	public int getRole() {
		return role;
	}

	public void setRole(int role) {
		this.role = role;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public List<User> getApplyUserList() {
		return applyUserList;
	}

	public void setApplyUserList(List<User> applyUserList) {
		this.applyUserList = applyUserList;
	}
	
	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	
	public ManageUserService getManageUserService() {
		return manageUserService;
	}

	public void setManageUserService(ManageUserService manageUserService) {
		this.manageUserService = manageUserService;
	}

	public List<User> getForgetPassUserList() {
		return forgetPassUserList;
	}

	public void setForgetPassUserList(List<User> forgetPassUserList) {
		this.forgetPassUserList = forgetPassUserList;
	}
}
